Remove nonsensical combinations of hardware choices from pull-downs.
authorrobertl <robertl>
Fri, 28 Aug 2009 17:21:37 +0000 (17:21 +0000)
committerrobertl <robertl>
Fri, 28 Aug 2009 17:21:37 +0000 (17:21 +0000)
gui/mainwindow.cpp
gui/mainwindow.h
gui/mainwinui.ui

index 7971fe6e84ce7f05c0a6e281c04442097c6db5c6..93c723787c24c01503405b05cfc63d7fc4a580d5 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: mainwindow.cpp,v 1.5 2009/08/28 17:08:55 robertl Exp $
+// $Id: mainwindow.cpp,v 1.6 2009/08/28 17:21:37 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -197,18 +197,41 @@ MainWindow::~MainWindow()
   if (upgrade)
     delete upgrade;
 }
+
 //------------------------------------------------------------------------
-void MainWindow::loadDeviceNameCombos()
+void MainWindow::loadInputDeviceNameCombo(QString format)
 {
   ui.inputDeviceNameCombo->clear();
+  // Later, we can probe the system for multiple USB devices and populate 
+  // here.
+  if (formatSupportsUSB(format))
+    ui.inputDeviceNameCombo->addItem("usb:");
+  if (formatSupportsSerial(format))
+    osLoadDeviceNameCombos(ui.inputDeviceNameCombo);
+  // If only one choice, just disable it.
+  ui.inputDeviceNameCombo->setEnabled(ui.inputDeviceNameCombo->count() > 1);
+}
+
+//------------------------------------------------------------------------
+void MainWindow::loadOutputDeviceNameCombo(QString format)
+{
   ui.outputDeviceNameCombo->clear();
-#if defined Q_OS_MAC
-  ui.inputDeviceNameCombo->addItem("usb:");
-  ui.outputDeviceNameCombo->addItem("usb:");
+  // Later, we can probe the system for multiple USB devices and populate 
+  // here.
+  if (formatSupportsUSB(format))
+    ui.outputDeviceNameCombo->addItem("usb:");
+  if (formatSupportsSerial(format))
+    osLoadDeviceNameCombos(ui.outputDeviceNameCombo);
+  // If only one choice, just disable it.
+  ui.outputDeviceNameCombo->setEnabled(ui.outputDeviceNameCombo->count() > 1);
+}
 
-  osLoadDeviceNameCombos(ui.inputDeviceNameCombo);
-  osLoadDeviceNameCombos(ui.outputDeviceNameCombo);
-#else
+//------------------------------------------------------------------------
+void MainWindow::loadDeviceNameCombos()
+{
+  loadInputDeviceNameCombo("");
+  loadOutputDeviceNameCombo("");
+#if defined Q_OS_MAC
   for (int i=0; deviceNames[i]; i++) {
     ui.inputDeviceNameCombo->addItem(deviceNames[i]);
     ui.outputDeviceNameCombo->addItem(deviceNames[i]);
@@ -374,7 +397,7 @@ void MainWindow::browseInputFile()
     QString str;
     for (int i=0; i<bd.inputFileNames.size(); i++) {
       if (i != 0)
-       str += ", ";
+        str += ", ";
       str += "\"" + bd.inputFileNames[i] + "\"";
     }
     ui.inputFileNameText->setText(str);
@@ -551,6 +574,18 @@ void MainWindow::setComboToFormat(QComboBox *comboBox, const QString &name, bool
   }
 }
 
+//------------------------------------------------------------------------
+bool MainWindow::formatSupportsUSB(QString format)
+{
+    return (format == "garmin" || format == "delbin");
+}
+
+//------------------------------------------------------------------------
+bool MainWindow::formatSupportsSerial(QString format)
+{
+    return (format != "delbin");
+}
+
 //------------------------------------------------------------------------
 void MainWindow::inputFormatChanged(int comboIdx)
 {
@@ -565,6 +600,8 @@ void MainWindow::inputFormatChanged(int comboIdx)
     bd.inputFileFormat =formatList[fidx].getName();
   else
     bd.inputDeviceFormat = formatList[fidx].getName();
+
+  loadInputDeviceNameCombo(formatList[fidx].getName());
 }
 
 //------------------------------------------------------------------------
@@ -582,6 +619,7 @@ void MainWindow::outputFormatChanged(int comboIdx)
   else if (ui.outputDeviceOptBtn->isChecked())
     bd.outputDeviceFormat = formatList[fidx].getName();
 
+  loadOutputDeviceNameCombo(formatList[fidx].getName());
 }
 
 //------------------------------------------------------------------------
@@ -931,6 +969,7 @@ void MainWindow::setWidgetValues()
     ui.inputDeviceOptBtn->setChecked(true);
     inputDeviceOptBtnClicked();
     setComboToFormat(ui.inputFormatCombo, bd.inputDeviceFormat, false);
+    loadInputDeviceNameCombo(bd.inputDeviceFormat);
     ui.inputStackedWidget->setCurrentWidget(ui.inputDevicePage);
   }
   setComboToDevice(ui.inputDeviceNameCombo, bd.inputDeviceName);
@@ -946,6 +985,7 @@ void MainWindow::setWidgetValues()
     ui.outputDeviceOptBtn->setChecked(true);
     outputDeviceOptBtnClicked();
     setComboToFormat(ui.outputFormatCombo, bd.outputDeviceFormat, false);
+    loadOutputDeviceNameCombo(bd.outputDeviceFormat);
     ui.outputStackedWidget->setCurrentWidget(ui.outputDevicePage);
   }
   else {
@@ -966,7 +1006,6 @@ void MainWindow::setWidgetValues()
   crossCheckInOutFormats();
   displayOptionsText(ui.inputOptionsText,  ui.inputFormatCombo, true);
   displayOptionsText(ui.outputOptionsText,  ui.outputFormatCombo, false);
-
   checkCharSetCombos();
   updateFilterStatus();
 }
index 04974e86130086998af6b40bc9aeea4aee7815ec..7d5968bdb42fedd480b14199b0e89f9bf3fbc0d7 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: mainwindow.h,v 1.4 2009/08/28 17:08:55 robertl Exp $
+// $Id: mainwindow.h,v 1.5 2009/08/28 17:21:37 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -68,6 +68,10 @@ private:
   void setComboToDevice(QComboBox *comboBox, const QString &);
 
   void loadDeviceNameCombos();
+  void loadInputDeviceNameCombo(QString format);
+  void loadOutputDeviceNameCombo(QString format);
+  bool MainWindow::formatSupportsUSB(QString format);
+  bool MainWindow::formatSupportsSerial(QString format);
   void loadCharSetCombos();
   void checkCharSetCombos();
   QString charSetFromCombo(QComboBox *);
index aae6063edd84f5088993cb893bdbcbc968ca2189..1e9a7ebe5cb78084ec1203e7a061c79a88878414 100644 (file)
                <property name="toolTip">
                 <string>Name of port to which input device is connected</string>
                </property>
+               <property name="sizeAdjustPolicy">
+                <enum>QComboBox::AdjustToContents</enum>
+               </property>
               </widget>
              </item>
              <item>
                <property name="toolTip">
                 <string>Name of port to which output device is connected</string>
                </property>
+               <property name="sizeAdjustPolicy">
+                <enum>QComboBox::AdjustToContents</enum>
+               </property>
               </widget>
              </item>
              <item>
      <x>0</x>
      <y>0</y>
      <width>674</width>
-     <height>26</height>
+     <height>22</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuFile">